package com.newly.common.base.exception.handler;

import cn.hutool.core.util.StrUtil;
import com.newly.common.base.entity.R;
import com.newly.common.base.exception.NewlyLoginException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: newly-parent
 * @remark: 登录异常
 * @author: guan
 * @create: 2022-01-28 10:58
 */
@RestControllerAdvice
@Slf4j
public class NewlyLoginExceptionHandle {

    @ExceptionHandler(NewlyLoginException.class)
    public R illegalArgumentExceptionHandle(NewlyLoginException e) {
        log.error("-----------------------------NewlyLoginException begin-----------------------------");
        String msg = StrUtil.isBlank(e.getMessage()) ? "参数处理异常" : e.getMessage();
        R<Object> failed = R.fail(e.getCode(), msg);
        log.error("error-> {}", failed);
        log.error("-----------------------------NewlyLoginException after-----------------------------");
        return failed;
    }
}
